<template>
  <div class="streams-container">
    <!-- 页面头部和统计卡片合并为一行 -->
    <div class="header-stats-row">
      <!-- 统计卡片 -->
      <el-row :gutter="8" class="stats-cards compact">
        <el-col :span="6">
          <el-card class="stat-card compact" :body-style="{ padding: '1px 8px', height: '48px', display: 'flex', alignItems: 'center', justifyContent: 'center' }">
            <div class="stat-content compact">
              <el-icon class="stat-icon compact"><VideoPlay /></el-icon>
              <div>
                <div class="stat-number compact">{{ stats.active }}</div>
                <div class="stat-label compact">直播中</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card compact" :body-style="{ padding: '1px 8px', height: '48px', display: 'flex', alignItems: 'center', justifyContent: 'center' }">
            <div class="stat-content compact">
              <el-icon class="stat-icon compact"><VideoPause /></el-icon>
              <div>
                <div class="stat-number compact">{{ stats.inactive }}</div>
                <div class="stat-label compact">等待流</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card compact" :body-style="{ padding: '1px 8px', height: '48px', display: 'flex', alignItems: 'center', justifyContent: 'center' }">
            <div class="stat-content compact">
              <el-icon class="stat-icon compact"><Warning /></el-icon>
              <div>
                <div class="stat-number compact">{{ stats.error }}</div>
                <div class="stat-label compact">已结束</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card compact" :body-style="{ padding: '1px 8px', height: '48px', display: 'flex', alignItems: 'center', justifyContent: 'center' }">
            <div class="stat-content compact">
              <el-icon class="stat-icon compact"><List /></el-icon>
              <div>
                <div class="stat-number compact">{{ stats.total }}</div>
                <div class="stat-label compact">总计</div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
      
      <div class="action-buttons">
        <el-button type="primary" @click="addStream" size="small">
          <el-icon><Plus /></el-icon>
          新建直播
        </el-button>
      </div>
    </div>

    <!-- 过滤和搜索 -->
    <el-row :gutter="16" class="filter-section compact">
      <el-col :span="14">
        <el-input
          v-model="searchQuery"
          placeholder="搜索直播名称"
          class="search-input"
          clearable
          @clear="handleSearch"
          @keyup.enter="handleSearch"
        >
          <template #prefix>
            <el-icon><Search /></el-icon>
          </template>
        </el-input>
      </el-col>
      <el-col :span="6">
        <el-select
          v-model="typeFilter"
          placeholder="流类型筛选"
          clearable
          @change="handleSearch"
          class="search-input"
        >
          <el-option label="全部类型" value="" />
          <el-option label="电视频道直播" value="tv_channel" />
          <el-option label="事件直播" value="event_live" />
          <el-option label="转播" value="relay" />
          <el-option label="推流" value="push_stream" />
          <el-option label="其他" value="other" />
        </el-select>
      </el-col>
      <el-col :span="4" style="display: flex; justify-content: flex-end;">
        <el-button
          type="primary"
          :icon="Refresh"
          @click="fetchStreams"
          style="height: 36px; border-radius: 6px; font-weight: 500; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); width: auto; min-width: 80px;"
        >
          刷新
        </el-button>
      </el-col>
    </el-row>

    <!-- 直播流列表 -->
    <el-card class="table-card">
      <el-table
        :data="paginatedStreams"
        v-loading="loading"
        stripe
        style="width: 100%"
        class="stream-table"
        :header-cell-style="{ background: '#f5f7fa', color: '#606266', fontWeight: '600', fontSize: '13px' }"
      >
        <el-table-column prop="name" label="名称" width="160" show-overflow-tooltip />
        <el-table-column prop="url" label="URL" min-width="280" show-overflow-tooltip />
        <el-table-column label="状态" width="100" align="center">
          <template #default="{ row }">
            <el-tag :type="getStatusType(row.status)" size="small">
              {{ getStatusText(row.status) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="流类型" width="100" align="center">
          <template #default="{ row }">
            <el-tag type="info" size="small">
              {{ getStreamTypeText(row.stream_type) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="录制任务" width="90" align="center">
          <template #default="{ row }">
            <el-tag :type="row.is_recording > 0 ? 'success' : 'info'" size="small">
              {{ row.is_recording > 0 ? '已配置' : '未配置' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="转码任务" width="110" align="center">
          <template #default="{ row }">
            <el-tag :type="row.is_transcode > 0 ? 'success' : 'info'" size="small">
              {{ row.is_transcode > 0 ? '已配置+' + row.is_transcode : '未配置' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="转推任务" width="110" align="center">
          <template #default="{ row }">
            <el-tag :type="row.is_pushing > 0 ? 'success' : 'info'" size="small">
              {{ row.is_pushing > 0 ? '已配置+' + row.is_pushing : '未配置' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="视频编码" width="100" align="center">
          <template #default="{ row }">
            {{ row.video_codec || '-' }}
          </template>
        </el-table-column>  
       
        <el-table-column label="分辨率" width="110" align="center">
          <template #default="{ row }">
            {{ row.resolution || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="码率" width="110" align="center">
          <template #default="{ row }">
            {{ formatBitrate(row.bitrate) }}
          </template>
        </el-table-column>
        <el-table-column label="帧率" width="90" align="center">
          <template #default="{ row }">
            {{ row.fps || 0 }}fps
          </template>
        </el-table-column>
              <el-table-column label="音频编码" width="100" align="center">
          <template #default="{ row }">
            {{ row.audio_codec || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="创建时间" width="150" align="center">
          <template #default="{ row }">
            {{ formatDateTime(row.created_at) }}
          </template>
        </el-table-column>
        <el-table-column label="更新时间" width="150" align="center">
          <template #default="{ row }">
            {{ formatDateTime(row.updated_at) }}
          </template>
        </el-table-column>
         <el-table-column label="创建用户" width="100" align="center">
          <template #default="{ row }">
            {{ row.act_uid || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="160" fixed="right" align="center">
          <template #default="{ row }">
            <div class="action-cell">
              <el-button-group>
                <el-tooltip content="配置任务" placement="top">
                  <el-button 
                    size="small" 
                    type="warning" 
                    :icon="Setting" 
                    circle
                    plain
                    @click="configureTask(row)"
                  />
                </el-tooltip>
                <el-tooltip :content="row.status === 'error' ? '启动流' : '停止流'" placement="top">
                  <el-button 
                    size="small" 
                    :type="row.status === 'error' ? 'success' : 'danger'"
                    :icon="row.status === 'error' ? VideoPlay : VideoPause" 
                    circle
                    plain
                    @click="toggleStreamStatus(row)"
                  />
                </el-tooltip>
                <el-tooltip content="查看详情" placement="top">
                  <el-button 
                    size="small" 
                    type="primary" 
                    :icon="View" 
                    circle
                    plain
                    @click="viewStream(row)"
                  />
                </el-tooltip>
                <el-tooltip content="编辑" placement="top">
                  <el-button 
                    size="small" 
                    type="success" 
                    :icon="Edit" 
                    circle
                    plain
                    @click="editStream(row)"
                  />
                </el-tooltip>
                <el-tooltip content="删除" placement="top">
                  <el-button 
                    size="small" 
                    type="danger" 
                    :icon="Delete" 
                    circle
                    plain
                    @click="deleteStream(row)"
                  />
                </el-tooltip>
              </el-button-group>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination-container">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
        :total="filteredStreams.length"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>

    <!-- 添加/编辑对话框 -->
    <el-dialog
      v-model="showAddDialog"
      :title="editingStream ? '编辑直播流' : '添加直播流'"
      width="500px"
    >
      <el-form
        ref="streamFormRef"
        :model="streamForm"
        :rules="streamRules"
        label-width="100px"
      >
        <el-form-item label="直播流名称" prop="name">
          <el-input v-model="streamForm.name" placeholder="请输入直播流名称" size="large" />
        </el-form-item>
        <el-form-item label="直播流URL" prop="url">
          <el-input v-model="streamForm.url" placeholder="请输入直播流URL" size="large" />
        </el-form-item>
        <el-form-item label="流类型" prop="stream_type">
          <el-select 
            v-model="streamForm.stream_type" 
            placeholder="请选择流类型"
            size="large"
          >
            <el-option label="电视频道直播" value="tv_channel" />
            <el-option label="事件直播" value="event_live" />
            <el-option label="转播" value="relay" />
            <el-option label="推流" value="push_stream" />
            <el-option label="其他" value="other" />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="showAddDialog = false">取消</el-button>
          <el-button type="primary" @click="handleSubmit">
            {{ editingStream ? '更新' : '添加' }}
          </el-button>
        </span>
      </template>
    </el-dialog>

    <!-- 任务配置对话框 -->
    <TaskConfigDialog
      v-model="showTaskConfigDialog"
      :stream="selectedStream"
      @success="handleTaskConfigSuccess"
    />
  </div>
</template>

<script setup>
import { ref, computed, onMounted, onUnmounted, reactive } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Plus, Search, Refresh, VideoPlay, VideoPause, Edit, Delete, View, Warning, List, Setting } from '@element-plus/icons-vue'
import streamApi from '@/api/stream'
import TaskConfigDialog from '@/components/TaskConfigDialog.vue'

// 响应式数据
const streams = ref([])
const loading = ref(false)
const total = ref(0)
const currentPage = ref(1)
const pageSize = ref(10)
const searchQuery = ref('')
const typeFilter = ref('')
const showAddDialog = ref(false)
const currentStream = ref({})
const editingStream = ref(null)
const showTaskConfigDialog = ref(false)
const selectedStream = ref(null)
const streamFormRef = ref()
const streamForm = reactive({
  name: '',
  url: '',
  stream_type: ''
})

// 表单验证规则
const streamRules = {
  name: [
    { required: true, message: '请输入直播流名称', trigger: 'blur' },
    { min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
  ],
  url: [
    { required: true, message: '请输入直播流URL', trigger: 'blur' },
    { type: 'url', message: '请输入有效的URL', trigger: 'blur' }
  ],
  stream_type: [
    { required: true, message: '请选择流类型', trigger: 'change' }
  ]
}

// 筛选后的直播流
const filteredStreams = computed(() => {
  let result = streams.value
  
  if (searchQuery.value) {
    result = result.filter(stream => 
      stream.name.toLowerCase().includes(searchQuery.value.toLowerCase()) ||
      stream.url.toLowerCase().includes(searchQuery.value.toLowerCase())
    )
  }
  
  if (typeFilter.value) {
    result = result.filter(stream => stream?.stream_type === typeFilter.value)
  }
  
  return result
})

// 分页后的直播流
const paginatedStreams = computed(() => {
  const start = (currentPage.value - 1) * pageSize.value
  const end = start + pageSize.value
  return filteredStreams.value.slice(start, end)
})

// 统计信息
const stats = computed(() => {
  const streamsData = Array.isArray(streams.value) ? streams.value : []
  return {
    active: streamsData.filter(s => s?.status === 'active').length,
    inactive: streamsData.filter(s => s?.status === 'inactive').length,
    error: streamsData.filter(s => s?.status === 'error').length,
    total: streamsData.length
  }
})

// 获取状态类型
const getStatusType = (status) => {
  const typeMap = {
    active: 'success',
    inactive: 'info',
    error: 'danger'
  }
  return typeMap[status] || 'info'
}

// 获取状态文本
const getStatusText = (status) => {
  const textMap = {
    active: '流正常',
    inactive: '等待流',  // 更新为更准确的描述
    error: '流结束'      // 更新为更准确的描述
  }
  return textMap[status] || status
}



// 获取流类型文本
const getStreamTypeText = (type) => {
  const typeMap = {
    tv_channel: '电视频道',
    event_live: '事件直播',
    relay: '转播',
    push_stream: '推流',
    other: '其他'
  }
  return typeMap[type] || '未分类'
}

// 格式化码率
const formatBitrate = (bitrate) => {
  if (!bitrate) return '0 kbps'
  if (bitrate < 1000) return bitrate + ' kbps'
  return (bitrate / 1000).toFixed(1) + ' Mbps'
}

// 格式化日期时间
const formatDateTime = (dateTime) => {
  if (!dateTime) return '-'
  const date = new Date(dateTime)
  return date.toLocaleString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit'
  })
}



// 查看直播流详情
const viewStream = (stream) => {
  currentStream.value = stream
  ElMessageBox.alert(
    `<div class="stream-detail">
      <div class="detail-section">
        <h3>${stream.name}</h3>
        <p class="stream-url">${stream.url}</p>
      </div>
      <div class="detail-section">
        <h4>实时画面</h4>
        <img 
          src="${stream.screenshot || '/default-screenshot.jpg'}" 
          alt="${stream.name}"
          class="detail-screenshot"
          onerror="this.src='/default-screenshot.jpg'"
        />
      </div>
      <div class="detail-grid">
        <div class="detail-item">
          <span class="label">状态:</span>
          <span class="value ${getStatusType(stream.status)}">${getStatusText(stream.status)}</span>
        </div>
        <div class="detail-item">
          <span class="label">录制任务:</span>
          <span class="value">${stream.record_task ? '启动' : '未启动'}</span>
        </div>
        <div class="detail-item">
          <span class="label">转推任务:</span>
          <span class="value">${stream.relay_task ? '启动' : '未启动'}</span>
        </div>
        <div class="detail-item">
          <span class="label">分辨率:</span>
          <span class="value">${stream.resolution || '-'}</span>
        </div>
        <div class="detail-item">
          <span class="label">码率:</span>
          <span class="value">${formatBitrate(stream.bitrate)}</span>
        </div>
        <div class="detail-item">
          <span class="label">帧率:</span>
          <span class="value">${stream.fps || 0}fps</span>
        </div>
        <div class="detail-item">
          <span class="label">创建时间:</span>
          <span class="value">${formatDateTime(stream.created_at)}</span>
        </div>
        <div class="detail-item">
          <span class="label">更新时间:</span>
          <span class="value">${formatDateTime(stream.updated_at)}</span>
        </div>
      </div>
    </div>`,
    '直播流详情',
    {
      dangerouslyUseHTMLString: true,
      customClass: 'stream-detail-dialog',
      confirmButtonText: '关闭'
    }
  )
}

// 获取直播流列表
const fetchStreams = async () => {
  loading.value = true
  try {
    const params = {
      search: searchQuery.value,
      type: typeFilter.value
    }
    const response = await streamApi.getStreams(params)
    streams.value = Array.isArray(response.items) ? response.items : []
    total.value = response.total || 0
  } catch (error) {
    console.error('获取直播流列表失败:', error)
    ElMessage.error('获取直播流列表失败，请检查服务器连接')
    streams.value = []
    total.value = 0
  } finally {
    loading.value = false
  }
}

// 处理分页大小变化
const handleSizeChange = (size) => {
  pageSize.value = size
  currentPage.value = 1
  fetchStreams()
}

// 处理当前页变化
const handleCurrentChange = (page) => {
  currentPage.value = page
  fetchStreams()
}

// 切换直播流状态
const toggleStream = async (stream) => {
  try {
    const action = stream.status === 'active' ? 'stop' : 'start'
    await api.post(`/streams/${stream.id}/${action}`)
    ElMessage.success(`${action === 'start' ? '启动' : '停止'}成功`)
    fetchStreams()
  } catch (error) {
    console.error('操作失败:', error)
    ElMessage.error('操作失败')
  }
}



// 添加直播流
const addStream = () => {
  editingStream.value = null
  streamForm.name = ''
  streamForm.url = ''
  streamForm.stream_type = ''
  showAddDialog.value = true
}

const editStream = (stream) => {
  editingStream.value = stream
  streamForm.name = stream.name
  streamForm.url = stream.url
  streamForm.stream_type = stream.stream_type || ''
  showAddDialog.value = true
}

// 删除直播流
const deleteStream = async (stream) => {
  try {
    await ElMessageBox.confirm(
      `确定要删除直播流 "${stream.name}" 吗？`,
      '确认删除',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
    )
    
    await streamApi.deleteStream(stream.id)
    ElMessage.success('删除成功')
    fetchStreams()
  } catch (error) {
    if (error !== 'cancel') {
      console.error('删除失败:', error)
      ElMessage.error('删除失败')
    }
  }
}



// 提交表单
const handleSubmit = async () => {
  try {
    await streamFormRef.value.validate()
    
    const formData = {
        name: streamForm.name,
        url: streamForm.url,
        stream_type: streamForm.stream_type,
        status: 'inactive',  // 创建时默认状态为inactive
        inuse: 1
        // act_uid 将由后端自动使用当前登录用户ID
      }
    
    if (editingStream.value) {
      // 编辑时只更新提供的字段
      const updateData = {
        name: streamForm.name,
        url: streamForm.url,
        stream_type: streamForm.stream_type
      }
      await streamApi.updateStream(editingStream.value.id, updateData)
      ElMessage.success('直播流更新成功')
    } else {
      await streamApi.createStream(formData)
      ElMessage.success('直播流创建成功')
    }
    
    showAddDialog.value = false
    await fetchStreams()
  } catch (error) {
    console.error('提交失败:', error)
    ElMessage.error(error.response?.data?.detail || '操作失败')
  }
}

// 配置任务
const configureTask = (stream) => {
  selectedStream.value = stream
  showTaskConfigDialog.value = true
}

// 切换直播流状态
const toggleStreamStatus = async (stream) => {
  try {
    const isError = stream.status === 'error'
    const action = isError ? 'start' : 'stop'
    const confirmText = isError ? '启动' : '停止'
    
    await ElMessageBox.confirm(
      `确定要${confirmText}直播流"${stream.name}"吗？`,
      `${confirmText}直播流`,
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: isError ? 'success' : 'warning'
      }
    )
    
    if (isError) {
          await streamApi.startStream(stream.id)
        } else {
          await streamApi.stopStream(stream.id)
        }
    ElMessage.success(`直播流已${confirmText}`)
    fetchStreams()
  } catch (error) {
    if (error !== 'cancel') {
      console.error('切换直播流状态失败:', error)
      ElMessage.error(error.response?.data?.detail || '切换直播流状态失败')
    }
  }
}

const handleTaskConfigSuccess = () => {
  showTaskConfigDialog.value = false
  fetchStreams()
}



// 搜索处理
const handleSearch = () => {
  currentPage.value = 1
  fetchStreams()
}

const resetFilters = () => {
  searchQuery.value = ''
  typeFilter.value = ''
  currentPage.value = 1
}

// 生命周期钩子
onMounted(() => {
  fetchStreams()
})
</script>

<style scoped>
.streams-container {
  padding: 12px;
  background-color: #f5f5f5;
  min-height: 80vh;
  overflow-x: hidden;
}

.header-stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

.stats-cards {
  flex: 1;
  margin: 0 !important;
}

.stat-card {
  height: 48px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
  border: 1px solid #e8e8e8;
}

.stat-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.stat-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.stat-icon {
  font-size: 20px;
  flex-shrink: 0;
  color: #409eff;
}

.stat-number {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  color: #333;
}

.stat-label {
  font-size: 12px;
  line-height: 1.2;
  color: #666;
}

.action-buttons {
  flex-shrink: 0;
}

.action-buttons .el-button {
  height: 36px;
  font-weight: 500;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.filter-section {
  margin-bottom: 12px;
}

.search-input {
  border-radius: 6px;
}

/* 新表格样式 */
.table-card {
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.stream-table :deep(.el-table__body tr) {
  height: 40px;
}

.action-cell {
  display: flex;
  justify-content: center;
  align-items: center;
}

.action-cell .el-button-group {
  display: flex;
  gap: 2px;
}

.action-cell .el-button {
  width: 24px;
  height: 24px;
  padding: 4px;
  transition: all 0.2s ease;
}

.action-cell .el-button:hover {
  transform: scale(1.1);
}

/* 详情对话框样式 */
:global(.stream-detail-dialog) {
  border-radius: 12px;
}

:global(.stream-detail) {
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

:global(.detail-section) {
  margin-bottom: 20px;
}

:global(.detail-section h3) {
  margin: 0 0 8px 0;
  color: #303133;
  font-size: 18px;
  font-weight: 600;
}

:global(.stream-url) {
  margin: 0;
  color: #909399;
  font-size: 14px;
  word-break: break-all;
}

:global(.detail-section h4) {
  margin: 0 0 12px 0;
  color: #606266;
  font-size: 16px;
  font-weight: 500;
}

:global(.detail-screenshot) {
  width: 100%;
  max-width: 400px;
  height: 225px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #e4e7ed;
  display: block;
  margin: 0 auto;
}

:global(.detail-grid) {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}

:global(.detail-item) {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #f5f7fa;
  border-radius: 6px;
}

:global(.detail-item .label) {
  color: #606266;
  font-weight: 500;
  font-size: 14px;
}

:global(.detail-item .value) {
  color: #303133;
  font-weight: 600;
  font-size: 14px;
}

:global(.detail-item .value.success) {
  color: #67c23a;
}

:global(.detail-item .value.warning) {
  color: #e6a23c;
}

:global(.detail-item .value.danger) {
  color: #f56c6c;
}

:global(.detail-item .value.info) {
  color: #909399;
}
</style>

// 停止直播流
const stopStream = async (stream) => {
  try {
    await ElMessageBox.confirm(
      `确定要停止直播流"${stream.name}"吗？`,
      '停止直播流',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
    )
    
    const response = await api.post(`/streams/${stream.id}/stop`)
    if (response.data.success) {
      ElMessage.success('直播流已停止')
      fetchStreams()
    } else {
      ElMessage.error(response.data.message || '停止失败')
    }
  } catch (error) {
    if (error !== 'cancel') {
      console.error('停止直播流失败:', error)
      ElMessage.error(error.response?.data?.detail || '停止直播流失败')
    }
  }
}